import React, { Component } from 'react'
//import PropTypes from 'prop-types'
import store from '../storeApp';

class Counter extends Component {
  constructor(props) {
    super(props);
    this.state={
      data:store.getState()
    }

  }

  renderSubscribe = () => {
    this.setState({
      data:store.getState()
    });
  }


  componentWillMount(){
    store.subscribe(this.renderSubscribe)
  }

  render() {
    const { data } = this.state;
    return (
      <p>
        Clicked: {data} times
        {' '}
        <button onClick={() => {store.dispatch({ type: 'INCREMENT' })}}>
          +
        </button>
        {' '}
        <button onClick={() => {store.dispatch({ type: 'DECREMENT' })}}>
          -
        </button>

      </p>
    )
  }
}

Counter.propTypes = {
  // value: PropTypes.number.isRequired,
  // onIncrement: PropTypes.func.isRequired,
  // onDecrement: PropTypes.func.isRequired
}

export default Counter
